package com.yanqu.road.server.channelserver.cmd.xrank.season;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.XRankProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.channelserver.manager.xrank.ChannelXRankMgr;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = ChannelProtocol.N_XRANK_GET_SEASON_REWARD, desc = "获取赛季排名发奖")
public class XRankGetSeasonRewardFromCrossCmd extends ChannelCommand {

    private int seasonId;
    private int systemId;
    private int type;
    private String rangeKey;
    private int channelId;
    private long serverId;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        XRankProto.CrossGetXRankSeasonRewardReqMsg reqMsg = XRankProto.CrossGetXRankSeasonRewardReqMsg.parseFrom(packet.getBytes());
        systemId = reqMsg.getSystemId();
        seasonId = reqMsg.getSeasonId();
        type = reqMsg.getType();
        rangeKey = reqMsg.getRangeKey();
        channelId = reqMsg.getChannelId();
        serverId = reqMsg.getServerId();
        userId = reqMsg.getUserId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        int myRank = ChannelXRankMgr.getSeasonUserRankMap().getUserRankListModel(systemId, seasonId, type, rangeKey).getMyRank(userId);

        XRankProto.GetXRankSeasonRewardFromCrossRespMsg.Builder builder = XRankProto.GetXRankSeasonRewardFromCrossRespMsg.newBuilder();
        builder.setSystemId(systemId);
        builder.setSeasonId(seasonId);
        builder.setType(type);
        builder.setRangeKey(rangeKey);
        builder.setMyRank(myRank);
        builder.setServerId(serverId);
        builder.setUserId(userId);
        YanQuMessage message = YanQuMessageUtils.buildMessage(Cross3Protocol.C3_XRANK_GET_SEASON_REWARD_FROM_CHANNEL, builder);
        ChannelMessageHelper.sendToChannel(message, channelId);
    }

    @Override
    public void sendData() {

    }
}
